{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Kinetica\n",
    "\n",
    "This notebooks goes over how to load documents from Kinetica"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install gpudb==7.2.0.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_community.document_loaders.kinetica_loader import KineticaLoader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Loading Environment Variables\n",
    "import os\n",
    "\n",
    "from dotenv import load_dotenv\n",
    "from langchain_community.vectorstores import (\n",
    "    KineticaSettings,\n",
    ")\n",
    "\n",
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Kinetica needs the connection to the database.\n",
    "# This is how to set it up.\n",
    "HOST = os.getenv(\"KINETICA_HOST\", \"http://127.0.0.1:9191\")\n",
    "USERNAME = os.getenv(\"KINETICA_USERNAME\", \"\")\n",
    "PASSWORD = os.getenv(\"KINETICA_PASSWORD\", \"\")\n",
    "\n",
    "\n",
    "def create_config() -> KineticaSettings:\n",
    "    return KineticaSettings(host=HOST, username=USERNAME, password=PASSWORD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_community.document_loaders.kinetica_loader import KineticaLoader\n",
    "\n",
    "# The following `QUERY` is an example which will not run; this\n",
    "# needs to be substituted with a valid `QUERY` that will return\n",
    "# data and the `SCHEMA.TABLE` combination must exist in Kinetica.\n",
    "\n",
    "QUERY = \"select text, survey_id from SCHEMA.TABLE limit 10\"\n",
    "kinetica_loader = KineticaLoader(\n",
    "    QUERY,\n",
    "    HOST,\n",
    "    USERNAME,\n",
    "    PASSWORD,\n",
    ")\n",
    "kinetica_documents = kinetica_loader.load()\n",
    "print(kinetica_documents)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_community.document_loaders.kinetica_loader import KineticaLoader\n",
    "\n",
    "# The following `QUERY` is an example which will not run; this\n",
    "# needs to be substituted with a valid `QUERY` that will return\n",
    "# data and the `SCHEMA.TABLE` combination must exist in Kinetica.\n",
    "\n",
    "QUERY = \"select text, survey_id as source from SCHEMA.TABLE limit 10\"\n",
    "kl = KineticaLoader(\n",
    "    query=QUERY,\n",
    "    host=HOST,\n",
    "    username=USERNAME,\n",
    "    password=PASSWORD,\n",
    "    metadata_columns=[\"source\"],\n",
    ")\n",
    "kinetica_documents = kl.load()\n",
    "print(kinetica_documents)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
